//
//  PresentView.m
//  Project two framework
//
//  Created by 张峥 on 16/7/25.
//  Copyright © 2016年 张峥. All rights reserved.
//

#import "PresentView.h"
#import "ZZConfig.h"
static PresentView   *presentView = nil;
static UIView           *shadeView;
static UIButton   *closeBtn = nil;

@interface PresentView ()
@property (nonatomic, strong) UIButton    *closeBtn;
@end

@implementation PresentView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self stepUI];
        
    }
    return self;
}

+ (instancetype)sharePresentView{
          if (presentView == nil) {
        presentView = [[PresentView alloc] initWithFrame: shadeView.bounds];
           presentView.center = CGPointMake(SCREEN_WIDTH/2,SCREEN_HEIGHT/2);
           presentView.bounds = CGRectMake(0, 0, 88, 60);
        presentView.backgroundColor = WHITE_C;
    }
           return presentView;
}

- (void)stepUI{
    closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [closeBtn setImage:[UIImage imageNamed:@"close_07"] forState:UIControlStateNormal];
        closeBtn.center = presentView.center;
    [closeBtn addTarget:self action:@selector(closeBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:closeBtn];
}

+ (void)showView {
    shadeView = [[UIView alloc] initWithFrame:SCREEN_Bounds];
    shadeView.alpha = 0;
    presentView.alpha = 0;
    shadeView.backgroundColor = BLACK_C;
    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    [window addSubview:shadeView];
    [window addSubview:presentView];
    [UIView animateWithDuration:1 animations:^{
        shadeView.alpha = 0.7;
        presentView.alpha = 0.8;
        presentView.center = CGPointMake(MID_X(shadeView.frame), MID_Y(shadeView.frame));
        presentView.bounds = CGRectMake(0, 0, 880, 600);
        closeBtn.center = CGPointMake(MAX_X(presentView.bounds)- CGRectGetWidth(presentView.bounds)/15, MIN_Y(presentView.bounds)+CGRectGetHeight(presentView.frame)/12 );
        closeBtn.bounds = CGRectMake(0, 0, CGRectGetWidth(presentView.bounds)/15, CGRectGetHeight(presentView.frame)/12);
    }];

}


#pragma mark   ---  点击事件
- (void)closeBtnClicked:(UIButton *)sender{
    [UIView animateWithDuration:1 animations:^{
        shadeView.alpha = 0;
        presentView.alpha = 0;
        presentView.center = CGPointMake(MID_X(shadeView.frame), MID_Y(shadeView.frame));
        presentView.bounds = CGRectMake(0, 0, 88, 60);
        closeBtn.center = CGPointMake(MAX_X(presentView.bounds)- CGRectGetWidth(presentView.bounds)/15, MIN_Y(presentView.bounds)+CGRectGetHeight(presentView.frame)/12 );
        closeBtn.bounds = CGRectMake(0, 0, 30,20);

    }];
 
}


////关闭按钮
//- (UIButton *)closeBtn
//{
//    if (!_closeBtn) {
//     
//    }
//    return _closeBtn;
//}


@end
